<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="feedbackList" @selection-change="handleSelectionChange">
      <el-table-column label="用户id" align="center" prop="userId"/>
      <el-table-column label="内容" align="center" prop="content"/>
      <el-table-column label="照片" align="center" prop="images">
        <template slot-scope="scope">
          <image-preview :src="scope.row.images" :width="80" :height="80"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="getInfo(scope.row)"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :visible.sync="open" width="800px" append-to-body>
      <el-descriptions title="反馈信息">
        <el-descriptions-item label="用户名">{{ form.userId }}</el-descriptions-item>
        <el-descriptions-item label="内容">{{ form.content }}</el-descriptions-item>
        <el-descriptions-item label="照片">
          <template slot-scope="scope">
            <image-preview :src="scope.row.images" :width="80" :height="80"/>
          </template>
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
import { getFeedback, listFeedback } from '@/api/debao/feedback'

export default {
  name: 'Feedback',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 意见反馈表格数据
      feedbackList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        content: null,
        images: null,
        createAt: null,
        updateAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询意见反馈列表 */
    getList() {
      this.loading = true
      listFeedback(this.queryParams).then(response => {
        this.feedbackList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    getInfo(row) {
      this.open = true
      getFeedback(row.id).then(resp => {
        this.form = resp.data
      })
    }
  }
}
</script>
